package day02;
//数据类型的演示

import java.math.BigDecimal;

public class DataTypeDemo {
    public static void main(String[] args) {

        //6）类型间的转换

        //1.整数直接量可以直接赋值给byte,short,char,但不能超出范围
        //2.byte,short,char型数据参与运算时，系统一律将其转换为int再运算

        byte b1 =5;
        byte b2 =6;
        byte b3 = (byte)(b1+b2);
        System.out.println(b3);
        System.out.println(2+2); //4
        System.out.println(2+'2'); //52
        System.out.println('2'+'2'); //100
        System.out.println('我'+'你'); //45425


        int a = 5;
        long b = a;//自动类型转换
        int c = (int)b; //强制类型转换

        long d = 5;//自动类型转换
        double e =5;//自动类型转换
        System.out.println(e);

        long f = 100000000000L;
        int g = (int)f;
        System.out.println(g); //1410065408, 强转有可能发生溢出

        double h = 25.678;
        int i = (int)h;
        System.out.println(i); //25,强转有肯坑丢失精度



        /*

        //5）char
        char c1 = '女'; //字符女
        char c2 = 'f'; //字符f
        char c3 = '6'; //字符6
        char c4 = ' '; //空格符

        //char c5 = 女;//编译错误，字符直接量必须放在单引号中
        //char c6 = '';//编译错误，必须有字符
        //char c7 = '10'//编译错误，只能装一个字符

        char c8 = 65; //0-65535
        System.out.println(c8); //println()时会依据c8的类型来做输出展示
                                //若c8为char型，则以字符形式展示
                                //若c8为int型，则以数字形式展示

        char c9 = '\'';
        System.out.println(c9);


         */


        /*
        //4）boolean
        boolean a = true; //true为布尔型直接量
        boolean b = false; //false为布尔型直接量
        //boolean c = 25; //编译错误，布尔型只能存储true或false
        */


        /*
        //3)double
        double a = 25.678; //25.678为小数直接量，默认为double类型
        float b = 25.678F; //25.678F为float类型直接量
        double c=3.0,d=2.9;
        System.out.println(c-d);//double类型可能出现误差
        double e=10.5,f=0.5;
        System.out.println(e+f);


         */






        /*
        //2)long
        long a = 25L; //25L为长整型直接量
        //long b = 10000000000;编译错误默认为int类型
        long c = 10000000000L;
        long d = 365L*24*60*60*1000; //去年一年所经历的毫秒数
        System.out.println(d);

        long e = 1000000000*2*10L;
        System.out.println(e);//200亿
        long f = 1000000000*3*10L;
        System.out.println(f);//不是300亿
        long g = 1000000000L*3*10;
        System.out.println(g);//300亿
        */






        /*
        //1)int
        int a = 250;
        System.out.println(5/2); //2
        System.out.println(5.0/2); //2.5
        System.out.println(5/2.0);   //2.5

        int d = 2147483647; //int 最大值
        d = d+1;
        System.out.println(d);

        long e =2147483647;;
        System.out.println(e);
        e+=1

                */
    }
}
